﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.IO.Ports;
using Modbus.Device;
using Modbus.Utility;
using System.Diagnostics;
namespace modBusTest
{
    class handleScript
    {
        //List<command> storage = new List<command>();
 // holds the list of commands       
        List<command> storage;
        //public string comPort { get; set; }
        //public int modbusId { get; set; }

//execute the list of commands  commands
        public void writeData()
        {
            foreach (command item in storage.ToArray())
            {
                item.writeValue();
            }


        }

// read the data and parse them into a set of commands
        public void readData(string fileName){
            storage = new List<command>();
            //command.comPort = comPort;
            //command.modbusId = modbusId;
            // command format:
            // read/write float/word adress (value to write)
            // r/w  f/w int  float/word

            StreamReader sr = new StreamReader(fileName);
            string lineToRead;
            while ((lineToRead = sr.ReadLine()) != null)
            {
                command temp = new command(lineToRead);

                //add it to our list
                storage.Add(temp);
            }
            sr.Close();
        }

//get the result of the commands
        public string [] getResults()
        {
            string[] temp = new string[storage.Count];
            

            for (int i = 0; i < storage.Count; i++)
            {
                temp[i] = storage[i].getResults()[0] + " , " + storage[i].getResults()[1] + " , " + storage[i].getResults()[2]; 
            }

            return temp;
            
        }

        
    }
}
